package br.sales.entity;

import java.io.Serializable;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

public class Newsletter implements Serializable{

	private String email;
	private boolean active;
	private long id;
	
	public Newsletter() {
	}
	
	public Newsletter(String email) {
		this.email = email;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public boolean isActive() {
		return active;
	}

	public void setActive(boolean ative) {
		this.active = ative;
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + (active ? 1231 : 1237);
		result = prime * result + ((email == null) ? 0 : email.hashCode());
		result = prime * result + (int) (id ^ (id >>> 32));
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Newsletter other = (Newsletter) obj;
		if (active != other.active)
			return false;
		if (email == null) {
			if (other.email != null)
				return false;
		} else if (!email.equals(other.email))
			return false;
		if (id != other.id)
			return false;
		return true;
	}

	public void copyFields(Object from) throws Exception {
		Class clazz = this.getClass();
		
		Field[] fields = clazz.getDeclaredFields();
		
		for (Field f: fields){
			Object object = f.get(from);
			if (object !=null && !Modifier.isFinal(f.getModifiers())){
				f.set(this,object);
			}
		}
		
		
	}
	
}
